import java.util.*;
/**
 * A token for representing declared keywords in
 * a comment.
 * 
 * @author James Stanier
 */
public class KeywordToken implements Comparable {
	private String keyword;
	private String sectionNumbers;
	private ArrayList<String> sectionNumberChecker;
	private ArrayList<String> sectionTitles;

	/**
	 * Constructor.
	 * @param s The declared keyword.
	 */
	public KeywordToken(String s) {
		keyword = s;
		sectionNumbers = "";
		sectionTitles = new ArrayList<String>();
		sectionNumberChecker = new ArrayList<String>();
	}

	/**
	 * Get the keyword this token represents.
	 * @return The keyword as a String.
	 */
	public String getKeyword() {
		return keyword;
	}

	/**
	 * Add a new section number reference for the declared
	 * keyword.
	 * @param i The section number as a String.
	 */
	public void addSectionNumber(String i) {
		sectionNumbers = "";
		if(sectionNumberChecker.isEmpty()) {
			sectionNumberChecker.add(i);
		}
		else if(!sectionNumberChecker.contains(i)) {
			sectionNumberChecker.add(i);
		}

		for(int j = 0; j < sectionNumberChecker.size(); j++) {
			if(j != sectionNumberChecker.size()-1) {
				sectionNumbers += sectionNumberChecker.get(j) + ", ";
			}
			else {
				sectionNumbers += sectionNumberChecker.get(j);
			}
		}
	}

	/**
	 * Manually set the section numbers.
	 * @param s New section numbers input.
	 */
	public void setSectionNumbers(String s) {
		sectionNumbers = s;
	}

	/**
	 * Add a section title.
	 * @param s The new section title.
	 */
	public void addSectionTitle(String s) {
		sectionTitles.add(s);
	}

	/**
	 * Get the section numbers belonging to this
	 * keyword.
	 * @return Section numbers as a String.
	 */
	public String getSectionNumbers() {
		return sectionNumbers;
	}

	/**
	 * Get the array of section titles.
	 * @return Array of section titles.
	 */
	public ArrayList<String> getSectionTitles() {
		return sectionTitles;
	}

	/**
	 * Compare method used for comparing keywords by name.
	 */
	public int compareTo(Object s) throws ClassCastException {
		if(s instanceof KeywordToken) {
			String a = this.getKeyword().toLowerCase();
			String b = ((KeywordToken)s).getKeyword().toLowerCase();
			return a.compareTo(b);
		}
		else {
			throw new ClassCastException("Object is not of type Symbol.");
		}
	}
}
